/**
 *<p>Copyright: CHINA NATIONAL SOFTWARE & SERVICE CO.,LTD.</p>
 */
package com.cssnb.commons.utils.page;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

/**
 * @Company: 中国软件与技术服务股份有限公司宁波子公司
 * @Project: 鄞州国税-信息化资产管理系统
 * @Module ID:
 * @Description:
 * @JDK version used: JDK1.4
 * @Author: 卜繁晟
 * @Email: 5545795@qq.com | bufsh@css.com.cn
 * @Created Date: 2013-4-23 上午11:35:18
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public class PageUtils {

	public static String CURPAGE = "curPage";
	public static int PAGESIZE = 15;

	/**
	 * @Author: 卜繁晟
	 * @Created Date: 2013-4-23 下午12:09:30
	 */
	public static Map getPageInfo(HttpServletRequest request, int totalCount){
		if(request != null){
			String pageNum = request.getParameter(PageUtils.CURPAGE);
			int pageNumber = 1, pageSize = PageUtils.PAGESIZE;
			if(pageNum != null){
				pageNumber = Integer.parseInt(pageNum);
			}
			if(request.getParameter("ps") != null){
				pageSize = Integer.parseInt(request.getParameter("ps"));
			}
			Map map = new HashMap();
			Page<Map> page = new Page<Map>(pageNumber, pageSize, totalCount);
			/**
			 * 以下参数为后台查询需要
			 */
			map.put("startRow", page.getThisPageFirstElementNumber());
			map.put("endRow", page.getThisPageLastElementNumber());
			/**
			 * 以下参数为分页类需要
			 */
			map.put("curPage", page.getThisPageNumber());
			map.put("pageSize", page.getPageSize());
			map.put("lastPage", page.getLastPageNumber());
			map.put("totalPage", page.getTotalPages());
			map.put("totalResult", page.getTotalElements());
			map.put("pageUrl", request.getRequestURL().toString());
			request.setAttribute("page", map);
			return map;
		}
		return null;
	}
}